﻿#region Regions

using System;
using System.IO;
using System.Text;

using FMWare.Core.Objects;

#endregion

namespace FMWare.Core.Base
{
	internal class BinaryReader : System.IO.BinaryReader
	{
		#region Constructors

		public BinaryReader(Stream input) : base(input) {}

		public BinaryReader(Stream input, Encoding encoding)
			: base(input, encoding) {}

		#endregion

		#region Public Methods

		public DateTime ReadDateTime()
		{
			short days = ReadInt16();
			short year = ReadInt16();

			DateTime dateTime = new DateTime(year, 1, 1);
			return dateTime.AddDays(days);
		}

		public Kit ReadKit()
		{
			Kit kit = new Kit {ForeColor = ReadInt16(), BackColor = ReadInt16(), Outline = ReadInt16(), Style = (KitStyle) ReadByte()};
			return kit;
		}

		public override string ReadString()
		{
			int length = ReadInt32();
			if (length == 0)
				return string.Empty;

			char[] text = ReadChars(length);
			ReadBytes(2); // Terminator
			return new string(text);
		}

		#endregion
	}
}